package com.kimho.menu.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.kimho.menu.domain.Menu;
import com.kimho.menu.service.MenuService;

@Controller
@RequestMapping("/menu")
public class MenuController {
	@Autowired
	private MenuService menuService;
	
	@RequestMapping(value="/menuList",method=RequestMethod.GET)
	public @ResponseBody Map<String,Object> getRoleList(HttpServletRequest request,   
            HttpServletResponse response){
		Map<String,Object> responseMap = new HashMap<String,Object>();
		List<Menu> menuList = menuService.getMenuList();
		responseMap.put("totalCount", menuList.size());
		responseMap.put("rows", menuList);
		return responseMap;
	}
	
	@RequestMapping(value="/costype")
	public @ResponseBody Map<String,Object> getCosttypeList(HttpServletRequest request,   
            HttpServletResponse response){
		Map<String,Object> responseMap = new HashMap<String,Object>();
		String parent_id = request.getParameter("parent_id");
		List<Menu> menuList = menuService.getCosttypeList(parent_id);
		responseMap.put("totalCount", menuList.size());
		responseMap.put("rows", menuList);
		return responseMap;
	}
}
